package cl.rizepe.playntest.core.listeners;

import static playn.core.PlayN.graphics;
import playn.core.GroupLayer;
import playn.core.Image;
import playn.core.Pointer.Event;
import pythagoras.f.Point;
import cl.rizepe.playntest.core.GestureManager.GestureManagerFactory;
import cl.rizepe.playntest.core.views.EffectedLayer;

public class DragCopy extends DragMove {
	GroupLayer layerList;
	protected GestureManagerFactory gestureManagerFactory;
	public DragCopy(EffectedLayer layer, GestureManagerFactory gestureManagerFactory) {
		super(layer);
		this.layerList=graphics().createGroupLayer();
		this.gestureManagerFactory=gestureManagerFactory;
	}
	
	public DragCopy(EffectedLayer layer,GroupLayer layerList, GestureManagerFactory gestureManagerFactory) {
		super(layer);
		this.layerList=layerList;
		this.gestureManagerFactory=gestureManagerFactory;
	}
	
	public DragCopy (EffectedLayer layer, Image image, float alphaShadow,GroupLayer layerList, GestureManagerFactory gestureManagerFactory){
		super( layer,  image,  alphaShadow);
		this.layerList=layerList;
		this.gestureManagerFactory=gestureManagerFactory;
	}
	
	
	@Override
	public void onPointerEnd(Event event) {
		/**/cloneLayer(event);

	    layerShadow.setVisible(false);
	/*
		layer.setTranslation(
				xRelativeStart+event.x()-xStart, 
				yRelativeStart+event.y()-yStart);/*/
	}
	public void cloneLayer(Event event) {

		
		EffectedLayer ils=layerState.clone();

		ils.setTranslation(
				newPostion(event).x(),
				newPostion(event).y() 
				);


		//layerList.add(ils);
		if (gestureManagerFactory!=null){
			ils.addListener(gestureManagerFactory.createGestureManager(ils));
			}
		if (layerList!=null)
		layerList.add(ils);
		
	}

	public Point newPostion(Event event) {
		return new Point(xRelativeStart+event.x()-xStart,yRelativeStart+event.y()-yStart);
	}
	
}
